package com.dynamixsoftware.printershare.snmp;

import java.io.ByteArrayOutputStream;

public class SNMPBERCodec
{
  public static final byte SNMPBITSTRING = 3;
  public static final byte SNMPCOUNTER32 = 65;
  public static final byte SNMPCOUNTER64 = 70;
  public static final byte SNMPGAUGE32 = 66;
  public static final byte SNMPGETNEXTREQUEST = -95;
  public static final byte SNMPGETREQUEST = -96;
  public static final byte SNMPGETRESPONSE = -94;
  public static final byte SNMPINTEGER = 2;
  public static final byte SNMPIPADDRESS = 64;
  public static final byte SNMPNSAPADDRESS = 69;
  public static final byte SNMPNULL = 5;
  public static final byte SNMPOBJECTIDENTIFIER = 6;
  public static final byte SNMPOCTETSTRING = 4;
  public static final byte SNMPOPAQUE = 68;
  public static final byte SNMPSEQUENCE = 48;
  public static final byte SNMPSETREQUEST = -93;
  public static final byte SNMPTIMETICKS = 67;
  public static final byte SNMPTRAP = -92;
  public static final byte SNMPUINTEGER32 = 71;
  public static final byte SNMPUNKNOWNOBJECT = 0;
  public static final byte SNMPv2BULKREQUEST = -91;
  public static final byte SNMPv2INFORMREQUEST = -90;
  public static final byte SNMPv2TRAP = -89;
  public static final byte SNMPv2pAUTHORIZEDMESSAGE = -95;
  public static final byte SNMPv2pCOMMUNICATION = -94;
  public static final byte SNMPv2pENCRYPTEDDATA = -95;
  public static final byte SNMPv2pENCRYPTEDMESSAGE = -95;
  
  public static byte[] encodeLength(int paramInt)
  {
    ByteArrayOutputStream localByteArrayOutputStream = new ByteArrayOutputStream();
    if (paramInt < 128)
    {
      byte[] arrayOfByte2 = new byte[1];
      arrayOfByte2[0] = ((byte)paramInt);
      localByteArrayOutputStream.write(arrayOfByte2, 0, 1);
    }
    for (;;)
    {
      return localByteArrayOutputStream.toByteArray();
      int i = 0;
      for (int j = paramInt; j > 0; j = (int)Math.floor(j / 256)) {
        i++;
      }
      localByteArrayOutputStream.write((byte)(128 + (byte)i));
      byte[] arrayOfByte1 = new byte[i];
      for (int k = i - 1; k >= 0; k--)
      {
        arrayOfByte1[k] = ((byte)(paramInt % 256));
        paramInt = (int)Math.floor(paramInt / 256);
      }
      localByteArrayOutputStream.write(arrayOfByte1, 0, i);
    }
  }
  
  public static SNMPObject extractEncoding(SNMPTLV paramSNMPTLV)
    throws SNMPBadValueException
  {
    switch (paramSNMPTLV.tag)
    {
    default: 
      return new SNMPUnknownObject(paramSNMPTLV.value);
    case 2: 
      return new SNMPInteger(paramSNMPTLV.value);
    case 48: 
      return new SNMPSequence(paramSNMPTLV.value);
    case 6: 
      return new SNMPObjectIdentifier(paramSNMPTLV.value);
    case 4: 
      return new SNMPOctetString(paramSNMPTLV.value);
    case 3: 
      return new SNMPBitString(paramSNMPTLV.value);
    case 64: 
      return new SNMPIPAddress(paramSNMPTLV.value);
    case 65: 
      return new SNMPCounter32(paramSNMPTLV.value);
    case 66: 
      return new SNMPGauge32(paramSNMPTLV.value);
    case 67: 
      return new SNMPTimeTicks(paramSNMPTLV.value);
    case 69: 
      return new SNMPNSAPAddress(paramSNMPTLV.value);
    case 70: 
      return new SNMPCounter64(paramSNMPTLV.value);
    case 71: 
      return new SNMPUInteger32(paramSNMPTLV.value);
    case -96: 
    case -95: 
    case -94: 
    case -93: 
      return new SNMPPDU(paramSNMPTLV.value, paramSNMPTLV.tag);
    }
    return new SNMPNull();
  }
  
  public static SNMPTLV extractNextTLV(byte[] paramArrayOfByte, int paramInt)
    throws SNMPBadValueException
  {
    SNMPTLV localSNMPTLV = new SNMPTLV();
    for (;;)
    {
      int j;
      int k;
      int i1;
      int n;
      try
      {
        localSNMPTLV.tag = paramArrayOfByte[paramInt];
        i = paramInt + 1;
        j = paramArrayOfByte[i];
        if (j < 0) {
          j += 256;
        }
        if (j / 128 >= 1) {
          break label165;
        }
        k = j;
        int m = i + 1;
        localSNMPTLV.totalLength = (k + (m - paramInt));
        ByteArrayOutputStream localByteArrayOutputStream = new ByteArrayOutputStream();
        localByteArrayOutputStream.write(paramArrayOfByte, m, k);
        localSNMPTLV.value = localByteArrayOutputStream.toByteArray();
        return localSNMPTLV;
      }
      catch (IndexOutOfBoundsException localIndexOutOfBoundsException)
      {
        int i;
        int i2;
        throw new SNMPBadValueException("Problem while decoding SNMP: packet truncated or corrupt");
      }
      catch (Exception localException)
      {
        throw new SNMPBadValueException("Problem while decoding SNMP");
      }
      if (i1 < n)
      {
        i++;
        i2 = paramArrayOfByte[i];
        if (i2 < 0) {
          i2 += 256;
        }
        k = i2 + k * 256;
        i1++;
        continue;
        label165:
        n = j % 128;
        k = 0;
        i1 = 0;
      }
    }
  }
}


/* Location:           C:\Users\Admin\Desktop\Decompiler\JAD\jd-gui-0.3.6.windows\classes_dex2jar.jar
 * Qualified Name:     com.dynamixsoftware.printershare.snmp.SNMPBERCodec
 * JD-Core Version:    0.7.0.1
 */